package thired.class01_sort;

public class Class02_SelectSort {
    public static void selectSort(int[] nums){
        if(nums == null || nums.length < 2){
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            int min = i;
            for (int j = i + 1; j < nums.length; j++) {
               min =  nums[j] > nums[min] ? min : j;
            }
            swap(nums,i,min);
        }
    }
    public static void swap(int[] nums,int i ,int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
    public static void main(String[] args) {
        int[] arr = new int[]{8,7,5,2,6,4,3,1,9};
        selectSort(arr);
        for (int i : arr) {
            System.out.print(i);
        }
    }
}
